#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	int n = 0;
	char ch1[10][10] = { 0 };
	char ch2[10][10] = { 0 };
	char ch3[10][10] = { 0 };
	scanf("%d", &n);

	int i = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%s", &ch1[i]);
	}
	for (i = 0; i < n; i++)
	{
		scanf("%s", &ch2[i]);
	}

	int count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[n - 1 - j][i])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("1");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[n - 1 - i][n - 1 - j])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("2");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[j][n - 1 - i])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("3");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[i][n - 1 - j])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("4");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[j][i])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("5");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[n - i - 1][j])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("5");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[n - j - 1][n - 1 - i])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("5");
		return 0;
	}
	count = 0;
	for (i = 0; i < n; i++)
	{
		int j = 0;
		for (j = 0; j < n; j++)
		{
			if (ch2[i][j] == ch1[i][j])
				count++;
		}
	}
	if (count == n * n)
	{
		printf("6");
		return 0;
	}
	printf("7");
	return 0;
}